//-----FSTATS_HEADER---------------
//--Footbal-Statistics-And-Forecast
//--Author:--Vitaly--Isaev---------
//--vitalyisaev2@gmail.com---------

#ifndef __FSTATS_H__
#define __FSTATS_H__



//-------------------------------
//-------INCLUDES----------------
//-------------------------------
#include <stdlib.h> //atoi
#include <iostream>
#include <fstream>
#include <vector> 
#include <algorithm>
#include <iomanip> 
#include <GL/glut.h> //OpenGL
using namespace std;



//-------------------------------
//-------TYPEDEFS----------------
//-------------------------------

//Structure for storing dates
struct date {
	unsigned short int day, month;
	unsigned int year;
};

//Structure for storing matches
struct match {
	date matchDate;
	string homeName, visitorName;
	unsigned short int homeScore, visitorScore, homePosition, visitorPosition;
	short int result; //'1' - home win, '0' - draw, '-1' - guest win;
};

struct tour {
	date tourDate;
	short int point, pointSumm;
	unsigned short int position;
};

//Structure for keeping timeline of matches of every day
struct team {
	string teamName;
	vector <tour> tourList;
};

struct currentTeamPosition {
	string teamName;
	short int pointSumm;
};

struct resultingMatrixCell {
	float gamePlayed, homeWins, draws, visitorWins;
	float homeWinsNorm, drawsNorm, visitorWinsNorm;
};



//-------------------------------
//-------GLOBALS-----------------
//-------------------------------

extern int start_tour;				//Tour start averaging from
extern vector <match> matchList; 	//List of matches
extern vector <team> teamList; 	//List of teams with inner lists of game played
extern ifstream input_file;		//input/output files
extern ofstream output_file;		//input/output files
extern vector <vector <resultingMatrixCell> > resultingMatrix; //Dynamical array to store results of matches
extern bool resultingMatrixIsInitialised; 

//-------------------------------
//-------PROTOTYPES--------------
//-------------------------------

//Parsing/printing text_file functions
date parseDate (string& tempLine);
match parseScore (string& tempLine, match& tempMatch);
void parsing (vector <match>& matchList, ifstream& input_file);
void printing (vector <vector <resultingMatrixCell> > & resultingMatrix, ofstream& output_file);

//Proceeding data functions
void getTeamList(vector <match>& matchList, vector <team>& teamList);
void fillTeamList (vector <match>& matchList, vector <team>& teamList);
void fillTeamTourList (vector <team>& teamList);
bool sortTeamPositions (currentTeamPosition a, currentTeamPosition b);
void getCurrentTeamPosition (vector <team>& teamList);
void returnPositionsToMatchList (vector <match>& matchList, vector <team>& teamList);
bool compareDates (date date1, date date2);
void createEmptyResultingMatrix(vector <vector <resultingMatrixCell> >& resultingMatrix, unsigned short size);
void fillResultingMatrix(vector <match>& matchList, vector <vector <resultingMatrixCell> >& resultingMatrix, unsigned short start_tour);
void normalizeResultingMatrix (vector <vector <resultingMatrixCell> >& resultingMatrix);
void flushDynamicalArraysAndStoreInfo (void);

//Graphics functions
void reshape (int w, int h);
void init();
void display();

#endif
